package com.gold.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.web.multipart.commons.CommonsMultipartFile;

public class Myutil {

	public static String getDateString() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		return sdf.format(new Date());
	}
	
	public static boolean checkStringNull(String... str) {
		for (int i = 0; i < str.length; i++) {
			if (str[i] == null || "".equals(str[i])) {
				return false;
			}
		}
		return true;
	}

	public static boolean checkFileNull(CommonsMultipartFile... file) {
		for (int i = 0; i < file.length; i++) {
			if (file[i] == null || "".equals(file[i].getOriginalFilename())) {
				return false;
			}
		}
		return true;
	}

	public static boolean checkNumberIsNumber(String... numberString) {
		Pattern p = Pattern.compile("\\d+");
		for (int i = 0; i < numberString.length; i++) {
			Matcher m = p.matcher(numberString[i]);
			if (m.matches() == false) {
				return false;
			}
		}
		return true;
	}

	public static boolean checkDoubleIsDouble(String... numberString) {
		Pattern p = Pattern.compile("(\\d+)||(\\d+[.]\\d+)");
		for (int i = 0; i < numberString.length; i++) {
			Matcher m = p.matcher(numberString[i]);
			if (m.matches() == false) {
				return false;
			}
		}
		return true;
	}

	public static String getPwd() {
		String pwd = "";
		for (int i = 0; i < 16; i++) {
			double d1 = Math.random();
			if (d1 < 0.33) {
				pwd += (char) (int) (Math.random() * 26 + 65);
			} else if (d1 < 0.66) {
				pwd += (char) (int) (Math.random() * 26 + 97);
			} else {
				pwd += (char) (int) (Math.random() * 10 + 48);
			}
		}
		return pwd;
	}

	public static void main(String[] args) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			long l1 = sdf.parse("2020-01-14 15:33:47.0").getTime();
			long l2 = sdf.parse("2020-01-15 15:33:47.0").getTime();
			System.out.println(l2 - l1);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

}
